#!/bin/bash
# Author: fanyongfeng
# 0  1 * * * /bin/bash /root/script/gitlab_data_backup.sh &> /backup/gitlab_data_backup/backup.log

TODAY=$(date +%Y%m%d)
MONTH=$(date +%Y_%m)
BACKUP_DIR=/backup/gitlab_data_backup

# 备份
/usr/bin/gitlab-rake gitlab:backup:create CRON=1

if [[ $? -eq 0 ]]
then
        echo "${TODAY} gitlab backup success"
else
        echo "${TODAY} gitlab backup failed"
        exit 1
fi

find ${BACKUP_DIR} -mtime +180 -type f | xargs -r -n 10 rm -f
mv /data/gitlab/backups/*${MONTH}*_gitlab_backup.tar ${BACKUP_DIR}